package cn.lger.icollege.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;

/**
 * Code that Changed the World
 * Pro said
 * Created by Pro on 2018-04-14.
 */
@Entity
@Setter
@Getter
@JsonIgnoreProperties({"hibernateLazyInitializer","handler"})
public class Attendance implements Serializable {

    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid")
    private String id;


    @ManyToOne(fetch = FetchType.LAZY)
    @JsonIgnore
    private Student student;

    @ManyToOne
    @JsonIgnoreProperties({"classrooms", "news", "role", "iconPath", "username"})
    private Teacher teacher;

    @ManyToOne
    @JsonIgnoreProperties({"attendances"})
    private AttendanceRecord record;
//
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
//    private Date createDate; // 考勤创建时间

    //自定义考勤名称
//    private String customerName = " "; //老师可以写入的考勤名称

//    @Temporal(TemporalType.TIMESTAMP) //声明字段时间类型
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date modifyDate; // 考勤创建时间

    //考勤备注
//    @Type(type = "text") //声明字段为text类型
    private String remark = " "; // 备注

    @OneToMany(mappedBy = "attendance", cascade = CascadeType.REMOVE)
    @JsonIgnore
    private Set<AttendanceMessage> messages; // 关于出勤的申诉通知

    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private AttendanceEnum attendance=AttendanceEnum.ok;//出勤情况

    public  enum AttendanceEnum{
        ok("出勤"),     //出勤
        late("迟到"),  // 迟到
        parse("请假"),  //请假
        no("缺勤");    //缺勤

        private String chineseName;

        AttendanceEnum(String chineseName){
            this.chineseName = chineseName;
        }

        public String getChineseName() {
            return chineseName;
        }
    }
}
